/**
	@file
	Contains functions for working with partitions.
	Mount/unmount/read/write etc.
	Relies on diskIO.h.
	Partitions are indexed by letters starting from 'a'.
	Maximum number of partitions is defined in \ref MAX_PARTITION_NUMBER.

	@author Konstantin Kastanov
*/
#ifndef PARTITIONING_H
#define PARTITIONING_H
#include "../../tools/headers/common.h"
#include "fat16.h"


#define MAX_PARTITION_NUMBER 16	/**< Specifies maximal number of mounted partitions*/
#define PARTITION_TABLE_SIZE 0x0F
#define FIRST_PARTITION_TABLE_ADDRESS 0x1BE /**< Address of the first primary 
												partition table on a drive*/

/**
	Corresponds a master partition table
	\todo Split CHS starting and ending addresses 
	(into separate cylinders, heads and sectors values)
	*/
struct Partition
{
	u8int bootIndicator;
	u32int startingCHS;
	u8int type;
	u32int endingCHS;
	u32int startingSector;
	u32int size; //In sectors
	//-----Not from Master partition table-----//
	u8int drive;
	u8int number;
	//---Boot block -------------//
	BootBlock bootBlock;
};
typedef struct Partition Partition;

extern void initPartitionning();
extern void getPartitionTable(u8int drive, u8int partitionNumber, Partition *res);
extern s8int mount(u8int drive, u8int partitionNumber);
extern u32int partRead(s8int partition, u8int *buff, u32int sectorNumber, u32int sectorCount);
extern u32int partWrite(s8int partition, u8int *buff, u32int sectorNumber, u32int sectorCount);
extern void readBootBlock(u8int *buff, BootBlock *res);
extern Partition* getMountedPartitionInfo(s32int partition);


#endif